package jp.co.systemi.asp.workflow;

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.apache.wicket.RequestCycle;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.protocol.http.WebRequest;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class SignInPage extends Main {
    private static final Logger log = Logger.getLogger(SignInPage.class.getName());
    public SignInPage() {
        RequestCycle rc = getRequestCycle();
        WebRequest wr = (WebRequest) rc.getRequest();
        HttpServletRequest sr = wr.getHttpServletRequest();
        String domain = sr.getServerName();
        UserService userService = UserServiceFactory.getUserService();
        String url = getRequestUrl(sr);
        log.info("url: " + url);
        String loginurl = userService.createLoginURL(url, domain);
        final Form<Object> form = new MainForm<Object>(this, "wi_loginForm");
        form.add(new ExternalLink("wi_adminLogin", loginurl));

        form.add(new ExternalLink("wi_top", url));
//        rc.setRequestTarget(new RedirectRequestTarget(url));
    }
}
